package cn.hls.web.servlet;

import hprose.common.HproseMethods;
import hprose.server.HproseServlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

@SuppressWarnings("serial")
public class ApiServlet extends HproseServlet{
	private APIService apiService=null;
	WebApplicationContext context = null;
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		context = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
		apiService= (APIService) context.getBean("apiService");
		super.init(config);
	}
	
	@Override
	protected void setGlobalMethods(HproseMethods methods) {
		methods.addInstanceMethods(apiService);
	}

	@Override
	public void destroy() {
		if(context!=null){
			context=null;
		}
		super.destroy();
	}
	
}
